<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<c:set var="userRoleDisplay" value="用户"/>
<c:if test="${not empty sessionScope.user}">
    <c:choose>
        <c:when test="${sessionScope.user.role == 'ADMIN'}">
            <c:set var="userRoleDisplay" value="管理员"/>
        </c:when>
        <c:when test="${sessionScope.user.role == 'PRODUCING'}">
            <c:set var="userRoleDisplay" value="生产人员"/>
        </c:when>
        <c:when test="${sessionScope.user.role == 'PROCESSING'}">
            <c:set var="userRoleDisplay" value="加工人员"/>
        </c:when>
        <c:when test="${sessionScope.user.role == 'CONSUMER'}">
            <c:set var="userRoleDisplay" value="消费者"/>
        </c:when>
    </c:choose>
</c:if>
<c:set var="userNameDisplay" value="${not empty sessionScope.user ? sessionScope.user.username : ''}"/>

<nav class="navbar navbar-expand-lg navbar-dark bg-custom-brown">
    <div class="container-fluid">
        <a class="navbar-brand" href="#">人参生态质控与溯源系统</a>
        <ul class="navbar-nav ms-auto">
            <li class="nav-item">
                <a class="nav-link" href="${pageContext.request.contextPath}/logout" onclick="return confirmLogout('${userRoleDisplay}', '${userNameDisplay}');">退出登录</a>
            </li>
        </ul>
    </div>
</nav>

<script>
function confirmLogout(role, username) {
    return confirm(role + (username ? ' ' + username : '') + '，是否退出登录？');
}
</script> 